<?php

$s = $_POST['s']??'';
//获取当前文件所在的绝对目录
$dir =  dirname(__FILE__)."/files".(($s)?('/'.$s):'');

$nameArr = $_POST['data']??'[]';
$nameArr && $nameArr = json_decode($nameArr,true);


$num = 0;
foreach($nameArr as  $row){
	$k = $row['old_name']??'';
	$v = $row['new_name']??'';
    $k = str_replace('/','',$k);
    $v = str_replace('/','',$v);
    $res = rename($dir.'/'.$k,$dir.'/'.$v);
    $res && $num = $num + 1;
}


echo json_encode($num,JSON_UNESCAPED_UNICODE);